package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao extends BaseStudentDao{
    ArrayList<Student> stuList = new ArrayList();

    public boolean addStudent(Student stu) {
        stuList.add(stu);
        return true;
    }

    public Student[] getStuArr() {
        Student[] stuArr = new Student[stuList.size()];
        for (int i = 0; i < stuList.size(); i++) {
            stuArr[i] = stuList.get(i);
        }
        return stuArr;
    }

    public void deleteStudentById(String id) {
        for (int i = 0; i < stuList.size(); i++) {
            Student stu = stuList.get(i);
            if(id.equals(stu.getId())){
                stuList.remove(i);
            }
        }
    }

    public void updateStudent(String id, Student stu) {
        for (int i = 0; i < stuList.size(); i++) {
            Student newStu = stuList.get(i);
            if(id.equals(newStu.getId())){
                stuList.set(i,stu);
            }
        }
    }
}
